package com.wxsong.authplatform.authweb.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class CarDynmicProxy implements InvocationHandler {

    private Car car;

    public CarDynmicProxy(Car car) {
        this.car = car;
    }

    public Car createProxy(){
        Car carProxy = (Car) Proxy.newProxyInstance(car.getClass().getClassLoader(),
                car.getClass().getInterfaces(), this);
        return carProxy;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String methodName = method.getName();
        System.out.println(methodName + "方法执行前");
        method.invoke(car, args);
        System.out.println(methodName + "方法执行后");
        return null;
    }
}
